import myAxios from "@/util/request";

/**
 * 获取所有门店列表
 */
export const listAllStores = () => {
  return myAxios({
    url: '/store/listAll',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('token')
    }
  });
};

/**
 * 获取门店商品列表
 */
export const listStoreProduct = (storeId: string) => {
  return myAxios({
    url: '/store/listProduct',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('token')
    },
    params: {
      storeId: storeId
    }
  });
};

/**
 * 获取门店商品详情
 */
export const storeProductDetail = (storeId: string, productId: number) => {
  return myAxios({
    url: '/store/storeProductDetail',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('token')
    },
    params: {
      storeId: storeId,
      productId: productId
    }
  });
};

/**
 * 添加门店
 * @param data 门店信息
 */
export const addStore = (data: {
  storeName: string;
  address: string;
  phone: string;
  openingHours: string;
  coverImage: string;
}) => {
  return myAxios({
    url: '/store/add',
    method: 'POST',
    headers: {
      'token': localStorage.getItem('token')
    },
    data
  });
};

/**
 * 修改门店
 * @param data 门店信息
 */
export const modify = (data: {
  storeId: string;
  name: string;
  address: string;
  phone: string;
  openingHours: string;
  coverImage: string;
  sort: number;
}) => {
  return myAxios({
    url: '/store/modify',
    method: 'POST',
    headers: {
      'token': localStorage.getItem('token')
    },
    data
  });
};

/**
 * 添加商品
 */
export function bindProduct(data: {
  storeId: string;
  productId: number;
  templateId: number;
  price: string;
}) {
  return myAxios({
    url: '/store/bindProduct',
    method: 'POST',
    headers: {
      'token': localStorage.getItem('token')
    },
    data
  });
}


/**
 * 删除门店
 */
export const delStore = (storeId: string) => {
  return myAxios({
    url: '/store/del',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('token')
    },
    params: {
      storeId: storeId
    }
  });
};

/**
 * 开张
 */
export const open = (storeId: string) => {
  return myAxios({
    url: '/store/open',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('adminToken')
    },
    params: {
      storeId: storeId
    }
  });
};

/**
 * 打样
 */
export const close = (storeId: string) => {
  return myAxios({
    url: '/store/close',
    method: 'GET',
    headers: {
      'token': localStorage.getItem('adminToken')
    },
    params: {
      storeId: storeId
    }
  });
};
